package org.lionsoul.dclock.util;


import com.sun.jna.platform.win32.Advapi32Util;
import com.sun.jna.platform.win32.WinReg;

public class RegistryUtil {

    public static void addStartup(String name, String path){

            Advapi32Util.registrySetStringValue(WinReg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", name, path);
    }

    public static void deleteStartup(String name){
        Advapi32Util.registryDeleteValue(WinReg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", name);
    }

    public static boolean isStartWithSystem(String name) {

        String dhRegister = getReg("Software\\Microsoft\\Windows\\CurrentVersion\\Run", name);

//        String dClock = WinRegistry.getString(WinRegistry.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", name);
        System.out.println("isStartWithSystem dhRegister :" + dhRegister);
        if (dhRegister != null && dhRegister.length() > 0){
            return true;
        }
        return false;
    }





    public static String getReg(String key, String valueName) {
        String value;

        try {
            value = Advapi32Util.registryGetStringValue(WinReg.HKEY_CURRENT_USER, key, valueName);
        } catch (Exception e) {
            value = "";
        }

        return value;
    }

}
